package com.luoc.spring.validateChain;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author luoc
 * @version 1.0
 * @date 2021/3/17 16:13
 * @since 1.0
 */
public class ValidateEmail extends ValidateChain {
    @Override
    public String validate(Object obj) {
        if(obj != null)
        {
            String s = "(^(\\w+)([\\-+.][\\w]+)*@(\\w[\\-\\w]*\\.){1,5}([A-Za-z]){2,6}$)";
            Pattern p = Pattern.compile(s);
            Matcher m = p.matcher(obj.toString());
            if(!m.matches()){
                return "电子邮箱格式不正确";
            }
        }
        return null;
    }
}
